﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Client
{
    /// <summary>
    /// Interaction logic for WinRegister.xaml
    /// </summary>
    public partial class WinRegister : Window
    {
        public WinRegister()
        {
            InitializeComponent();
            Grid_Root.DataContext = Client_Register;
            SetUpEvent();
            this.Loaded -= new RoutedEventHandler(WinRegister_Loaded);
            this.Loaded += new RoutedEventHandler(WinRegister_Loaded);
        }

        void WinRegister_Loaded(object sender, RoutedEventArgs e)
        {
            TextBox_SupplierName.Focus();
        }
        public Share.Data.Client Client_Register = new Share.Data.Client ();
        void SetUpEvent()
        {
            Button_Cancel.Click -= new RoutedEventHandler(Button_Cancel_Click);
            Button_Cancel.Click += new RoutedEventHandler(Button_Cancel_Click);

            Button_Register.Click -= new RoutedEventHandler(Button_Register_Click);
            Button_Register.Click += new RoutedEventHandler(Button_Register_Click);

            Button_Close.Click -= new RoutedEventHandler(Button_Close_Click);
            Button_Close.Click += new RoutedEventHandler(Button_Close_Click);
        }

        void Button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            Client_Register.Refresh(); 
        }
        void Button_Register_Click(object sender, RoutedEventArgs e)
        {
            string notice = CheckInvalid();
            if (string.IsNullOrEmpty(notice))
            {
                this.Close();
            }
            else
            {
                MessageBox.Show(notice);
            }
        }
        void Button_Close_Click(object sender, RoutedEventArgs e)
        {
            Client_Register.Refresh(); 
            this.Close();
        }

        public string CheckInvalid()
        {
            if (string.IsNullOrEmpty(Client_Register.SupplierName))
                return "Please Input Full Name";
            return string.Empty;
        }

    }
}
